package cn.paidaxin.utils;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.teaopenapi.models.Config;

/**
 * @author pai dx
 * @Description
 * @date 2021-10-26 09:50
 **/
public class AliSmsUtils {


    private static Client createClient(String accessKeyId,String accessKeySecret) throws Exception {
        Config config = new Config().setAccessKeyId(accessKeyId).setAccessKeySecret(accessKeySecret);
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new Client(config);
    }

    /**
     * 阿里短信推送
     * @return 成功失败
     */
    public static SendSmsResponse smsPush(String phoneNum,String msg,String accessKeyId,String accessKeySecret) throws Exception {
        Client client = AliSmsUtils.createClient(accessKeyId, accessKeySecret);
        SendSmsRequest smsRequest = new SendSmsRequest();

        //短信接收人电话号码（无前缀11位电话号码）
        smsRequest.setPhoneNumbers(phoneNum);
        //短信签名名称
        smsRequest.setSignName("草样年华");
        //短信模板id
        smsRequest.setTemplateCode("SMS_162520874");

        smsRequest.setTemplateParam("{\"code\":\""+msg+"\"}");

        return client.sendSms(smsRequest);
    }
}
